import { SysCustomWidgetType } from '@/staticDict/index.js';

export function getAllWidgetList (rootList) {
  function addWidgetToList (widget, widgetList = []) {
    widgetList.push(widget);
    if (Array.isArray(widget.childWidgetList)) {
      widget.childWidgetList.forEach(subWidget => {
        addWidgetToList(subWidget, widgetList);
      });
    }
  }

  let temp = [];
  if (Array.isArray(rootList)) {
    rootList.forEach(widget => {
			// console.log(widget)
      addWidgetToList(widget, temp);
    });
  }
  return temp;
}


export function isChart (widgetType) {
  return [
    SysCustomWidgetType.LineChart,
    SysCustomWidgetType.BarChart,
    SysCustomWidgetType.PieChart,
    SysCustomWidgetType.ScatterChart,
    SysCustomWidgetType.PivotTable,
    SysCustomWidgetType.DataViewTable,
    SysCustomWidgetType.Carousel,
    SysCustomWidgetType.RichText,
    SysCustomWidgetType.GaugeChart,
    SysCustomWidgetType.RadarChart,
    SysCustomWidgetType.FunnelChart,
    SysCustomWidgetType.ProgressBar,
    SysCustomWidgetType.ProgressCircle,
    SysCustomWidgetType.DataCard,
    SysCustomWidgetType.DataProgressCard,
    SysCustomWidgetType.CommonList
  ].indexOf(widgetType) !== -1;
}
